
*REPLICATION CODE FOR "Licensing Life-Saving Drugs for Developing Countries: Evidence from the Medicines Patent Pool" Figure 2

*The analysis exploits proprietary data purchased from IQVIA which cannot be shared. Please refer to the readme file for information on the variables used and the sample coverage.  





u IQVIA_country_drugs.dta, clear 
set more off

gen id = product+country
encode id, gen(ID)
drop id


bys ID: gen year_=year if MPP==1
bys ID: egen year_switch=min(year_)
gen time_to_treat=year-year_switch

encode product, gen(product_code)
encode country, gen(country_code)


replace time_to_treat = 0 if missing(year_switch)
g treat = !missing(year_switch)

summ time_to_treat
g shifted_ttt = time_to_treat - r(min)
summ shifted_ttt if time_to_treat == -1
local true_neg1 = r(mean)

drop if time_to_treat<-4


*USE THIS LINE TO OBATAIN THE GRAPH IN PANEL A
reghdfe one_gen ib`true_neg1'.shifted_ttt, a(ID year) vce(cluster product_code country_code)

*USE THIS LINE TO OBATAIN THE GRAPH IN PANEL B
*reghdfe logSales ib`true_neg1'.shifted_ttt zeroSales, a(ID year) vce(cluster product_code country_code)

*USE THIS LINE TO OBATAIN THE GRAPH IN PANEL C
*reghdfe logVolume ib`true_neg1'.shifted_ttt zeroSales, a(ID year) vce(cluster product_code country_code)



g coef = .
g se = .

levelsof shifted_ttt, l(times)
foreach t in `times' {
	replace coef = _b[`t'.shifted_ttt] if shifted_ttt == `t'
	replace se = _se[`t'.shifted_ttt] if shifted_ttt == `t'
}





g ci_top = coef+1.64*se
g ci_bottom = coef - 1.64*se

keep time_to_treat coef se ci_*
duplicates drop

sort time_to_treat

summ ci_top
local top_range = r(max)
summ ci_bottom
local bottom_range = r(min)

twoway (sc coef time_to_treat, connect(line)) ///
	(rcap ci_top ci_bottom time_to_treat)	///
	(function y = 0, range(time_to_treat)) ///
	(function y = 0, range(`bottom_range' `top_range') horiz), ///
	xtitle("Time to Treatment") caption("90% confidence intervals shown") legend(off)


